#! /usr/bin/env python

import sys

from compilerfactory import CompilerFactory

hostname = 'localhost'
port = 9090

usage = """
usage:

compiler [-h] [-r hostname] [-p port]

where :
	-r | --remotehost = host where the nameserver is running 
        -p | --port = the name server port
        -h | --help = print help
"""

def parseOptions():
    """
    This method parses the options in sys.argv
    """
    argv = sys.argv[1:]
    try:
        opts, args = getopt.gnu_getopt(argv, 
                                   "hr:p",
                                   ["help", "remotehost=", "port="])
    except getopt.GetoptError, ex:
        print '\nError:\t', ex
        exitfn()
    
    for opt, arg in opts:
        if opt in ("-h", "-help"):
            exitfn()
        elif opt in ("-r", "--host"):
            global hostname
            hostname = arg
        elif opt in ("-p", "--port"):
            global port
            port = arg
    
    if len(args) != 2:
        usage()
        sys.exit(2)


def exitfn():
    print usage
    sys.exit(0)
  
    
def main():
    parseOptions()


if __name__ == '__main__':
    main()